﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Visifire.Charts;
using Marking.Dashboard.Infrastructures;
using Marking.Dashboard.ViewModels.Stock;

namespace Marking.Dashboard.Views.Stock
{
    public partial class StockColumnChartView : UserControl
    {
        public StockColumnChartView()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty ReportUrlProperty = DependencyProperty.Register(
            "ReportUrl", typeof(string), typeof(StockColumnChartView), null);

        public string ReportUrl
        {
            get
            {
                return (string)this.GetValue(ReportUrlProperty);
            }
            set
            {
                this.SetValue(ReportUrlProperty, value);
            }
        }

        private void DataSeries_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.ReportUrl))
            {
                return;
            }

            var data = (sender as DataPoint);

            var stockInfo = (this.DataContext as StockColumnChartViewModel)
                .FirstOrDefault(x => x.Warehouse == data.AxisXLabel);

            if (stockInfo == null)
            {
                return;
            }

            ReportHelper.Show(this.ReportUrl, new
            {
                stockInfo.WarehouseId
            });
        }
    }
}
